package com.example.audio_test.ui

import android.Manifest
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.audio_test.R
import com.kun.base.ui.AbsBaseActivity
import kotlinx.android.synthetic.main.activity_media_main.*
import permissions.dispatcher.NeedsPermission
import permissions.dispatcher.RuntimePermissions

/**
 *音视频练习主页
 * 各页面入口
 *
 * @author : Kun
 * @date : 2021/6/24
 * @time : 11:35
 */
@RuntimePermissions
@Route(path = "/recordTest/MediaMainActivity")
class MediaMainActivity : AbsBaseActivity() {
    override fun getLayoutId(): Int {
        return R.layout.activity_media_main
    }

    override fun initViewModel() {
    }

    override fun initView() {
        tv_record.setOnClickListener {
            //音频录制
            ARouter.getInstance().build("/recordTest/RecordActivity").navigation()
        }
        tv_video.setOnClickListener {
            //视频画面录制
            ARouter.getInstance().build("/recordTest/VideoActivity").navigation()
        }
        tv_video_play.setOnClickListener {
            //视频播放
            ARouter.getInstance().build("/recordTest/IjkPlayerActivity").navigation()
        }

        tv_media_recorder.setOnClickListener {
            toMediaRecorderWithPermissionCheck()
        }

        tv_video_recorder.setOnClickListener {
            toVideoRecorderWithPermissionCheck()
        }

        tv_gl_surface.setOnClickListener {
            toGlSurfaceViewWithPermissionCheck()
        }
    }

    @NeedsPermission(
        Manifest.permission.CAMERA,
        Manifest.permission.WRITE_EXTERNAL_STORAGE,
        Manifest.permission.RECORD_AUDIO
    )
    fun toMediaRecorder(){
        //mediaRecorder录制视频
        ARouter.getInstance().build("/recordTest/MediaRecorderActivity").navigation()
    }

    @NeedsPermission(
        Manifest.permission.CAMERA,
        Manifest.permission.WRITE_EXTERNAL_STORAGE,
        Manifest.permission.RECORD_AUDIO
    )
    fun toVideoRecorder(){
        ARouter.getInstance().build("/recordTest/VideoRecordActivity").navigation()
    }

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        onRequestPermissionsResult(requestCode, grantResults)
    }
    @NeedsPermission(
        Manifest.permission.CAMERA
    )
    fun toGlSurfaceView(){
        ARouter.getInstance().build("/recordTest/GlSurfaceViewActivity").navigation()
    }
}